<script>
function disp_me(str) {
  Element.hide('loading');
  if(str!='0') {alert(str);return;}
  $('notice').update("OK");
  new Effect.Highlight('notice',{duration:3});     
  }
   
function send(data) {
  Element.show('loading');
  $('notice').innerHTML = "&nbsp;";
  new Ajax.Request('/myinfo/update', {asynchronous:true, evalScripts:true, onComplete:function(request){disp_me(request.responseText)}, parameters:Form.serialize(data)});
  }   
   
function verify() {
  if($('user_name').value=="" || $('user_email').value=="") {
    alert('Your name or email can not be empty');
    return false;
    }
  send('data');
  }
   
function ch_pwd_verify() {
  send('data_pwd');
  }

function ch_mail_options_verify() {
  send('mail_options');
  }
   
</script>

<h2><%=I18n.t(:title_my_profile)%></h2>
<%
e = @user.email

if e != nil and  e != ''-%>
<a href="http://www.gravatar.com/"><img align="left" src="http://www.gravatar.com/avatar.php?gravatar_id=<%=Digest::MD5.hexdigest(e)%>"></a>
<% end -%>

<% form_tag do %>
<table id="data">
<tr><td><%=I18n.t(:name)%></td><td><%= text_field(:user, :name, {:size => 25}) %></td></tr>
<tr><td><%=I18n.t(:email)%></td><td><%= text_field(:user, :email, {:size => 25}) %></td></tr>
<tr><td>&nbsp;</td><td><%= button_to_function(I18n.t(:save), "verify()", {:class => 'button'}) %>
<img id='loading' style="display:none;" src='/images/loading.gif'></td></tr>
</table>
<% end %>
<br />
<br />
<br />


<h2><%=I18n.t(:title_change_my_pwd)%></h2>
<% form_tag :action => 'update' do %>
<table id="data_pwd">
<tr><td><%=I18n.t(:pwd)%></td><td><%= password_field(:user, :password, {:size => 15}) %></td></tr>
<tr><td><%=I18n.t(:pwd_confirm)%></td><td><%= password_field(:user, :password_confirmation, {:size => 15}) %> <%=I18n.t(:expl_pwd_confirm)%></td></tr>
<tr><td>&nbsp;</td><td><%= button_to_function(I18n.t(:save), "ch_pwd_verify()", {:class => 'button'}) %></td></tr>
</table>
<% end %>
<br />
<br />

<!--
<h2>Option d'email</h2>
<% form_tag  do %>
<table id="mail_options">
<tr><td><%#= check_box(:user, :want_mail) %></td><td>envoi d'emails journaliers si nouveaux films</td></tr>
<tr><td>&nbsp;</td><td><%= button_to_function("Sauver", "ch_mail_options_verify()", {:class => 'button'}) %></td></tr>
</table>
<% end %>
-->
